<?php

namespace App\Admin\Actions;

use App\Models\Client;
use Encore\Admin\Actions\BatchAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class LingQu extends BatchAction
{
    public $name = '批量领取';

    public function handle(Collection $collection,Request $request)
    {
        $emp = Admin::user()->id;

        $ids = [];
        foreach ($collection as $model){
            array_push($ids,$model['id']);
        }

        $rs = Client::query()->whereIn('id',$ids)->update(['employee_id'=>$emp,'in_sea'=>2,'true_client'=>1]);

        if($rs > 0){
            return $this->response()->success('成功领取 '. $rs . ' 个客户')->refresh();
        }else{
            return $this->response()->error('成功领取 '. $rs . ' 个客户')->refresh();
        }

    }


}
